package com.ddxcloud.movie.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ddxcloud.common.annotation.RepeatSubmit;
import com.ddxcloud.common.utils.Result;
import com.ddxcloud.movie.data.dto.BindCouponDTO;
import com.ddxcloud.movie.service.CouponsService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/coupons")
@Api(tags="卡券")
public class CouponsController {

    @Resource
    CouponsService couponsService;

    /**
     * 优惠券列表
     * @param request
     * @return
     */
    @Operation(summary = "优惠券列表")
    @GetMapping("/getCouponList")
    public Result<?> getCouponList(HttpServletRequest request) {
        return Result.success(couponsService.getCouponList(request));
    }

    /**
     * 优惠券详情
     * @param couponCode
     * @return
     */
    @Operation(summary = "优惠券详情")
    @GetMapping("/getCodeInfo")
    public Result<JSONObject> getCodeInfo(String couponCode) {
        return Result.success(couponsService.getCodeInfo(couponCode));
    }

    /**
     * 绑定优惠券
     * @param dto
     * @param request
     * @return
     */
    @RepeatSubmit
    @Operation(summary = "绑定优惠券")
    @PostMapping("/bind")
    public Result<Boolean> bind(@RequestBody BindCouponDTO dto, HttpServletRequest request) {
        return Result.success(couponsService.bind(dto, request));
    }
}
